<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="投保人名称" prop="toubaoId">
        <el-select v-model="queryParams.toubaoId" placeholder="请选择投保人名称" clearable>
          <el-option
              v-for="dict in taobaoList"
              :key="dict.deptId"
              :label="dict.deptName"
              :value="dict.deptId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="被保险人名称" prop="beibaoId">
        <el-select v-model="queryParams.beibaoId" placeholder="请选择被保险人名称" clearable>
          <el-option
              v-for="dict in taobaoList"
              :key="dict.deptId"
              :label="dict.deptName"
              :value="dict.deptId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="保险人名称" prop="baoxianId">
        <el-select v-model="queryParams.baoxianId" placeholder="请选择保险人名称" clearable>
          <el-option
              v-for="dict in baoxianList"
              :key="dict.deptId"
              :label="dict.deptName"
              :value="dict.deptId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="经纪/代理公司名称" prop="proxyId" label-width="130px">
        <el-select v-model="queryParams.proxyId" placeholder="请选择经纪/代理公司名称" clearable>
          <el-option
              v-for="dict in proxyList"
              :key="dict.deptId"
              :label="dict.deptName"
              :value="dict.deptId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="险种" prop="insureType" label-width="50">
        <el-select v-model="queryParams.insureType" placeholder="险种" clearable>
          <el-option
              v-for="dict in dict.type.insure_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!--<el-row :gutter="10" class="mb8">-->
    <!--  <el-col :span="1.5">-->
    <!--    <el-button-->
    <!--        type="primary"-->
    <!--        plain-->
    <!--        icon="el-icon-plus"-->
    <!--        size="mini"-->
    <!--        @click="handleAdd"-->
    <!--        v-hasPermi="['insurance:settle:add']"-->
    <!--    >新增-->
    <!--    </el-button>-->
    <!--  </el-col>-->
    <!--  <el-col :span="1.5">-->
    <!--    <el-button-->
    <!--        type="success"-->
    <!--        plain-->
    <!--        icon="el-icon-edit"-->
    <!--        size="mini"-->
    <!--        :disabled="single"-->
    <!--        @click="handleUpdate"-->
    <!--        v-hasPermi="['insurance:settle:edit']"-->
    <!--    >修改-->
    <!--    </el-button>-->
    <!--  </el-col>-->
    <!--  <el-col :span="1.5">-->
    <!--    <el-button-->
    <!--        type="danger"-->
    <!--        plain-->
    <!--        icon="el-icon-delete"-->
    <!--        size="mini"-->
    <!--        :disabled="multiple"-->
    <!--        @click="handleDelete"-->
    <!--        v-hasPermi="['insurance:settle:remove']"-->
    <!--    >删除-->
    <!--    </el-button>-->
    <!--  </el-col>-->
    <!--  <el-col :span="1.5">-->
    <!--    <el-button-->
    <!--        type="warning"-->
    <!--        plain-->
    <!--        icon="el-icon-download"-->
    <!--        size="mini"-->
    <!--        @click="handleExport"-->
    <!--        v-hasPermi="['insurance:settle:export']"-->
    <!--    >导出-->
    <!--    </el-button>-->
    <!--  </el-col>-->
    <!--  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    <!--</el-row>-->
    <el-table v-loading="loading" :data="settleList" @selection-change="handleSelectionChange">
      <!--<el-table-column type="selection" width="55" align="center"/>-->
      <el-table-column label="保单号码" align="center" prop="insureNo"/>
      <el-table-column label="合同名称" align="center" prop="contractName"/>
      <el-table-column label="保险金额(元)" align="center" prop="insureAmount"/>
      <el-table-column label="赔案数量" align="center" prop="settleNum"/>
      <el-table-column label="已结案数量" align="center" prop="completeNum"/>
      <el-table-column label="总计报损金额(元)" align="center" prop="totalAmount"/>
      <el-table-column label="已决赔款(元)" align="center" prop="completeAmount"/>
      <el-table-column label="已决赔付率(%)" align="center" prop="rate"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="addSettle(scope.row)"
          >理赔
          </el-button>
          <!--<router-link :to="'/insurance/settle/settle-index' + scope.row.insureId" class="link-type">-->
          <!--  <span>理赔</span>-->
          <!--</router-link>-->
          <!--<el-button-->
          <!--  size="mini"-->
          <!--  type="text"-->
          <!--  icon="el-icon-delete"-->
          <!--  @click="handleDelete(scope.row)"-->
          <!--  v-hasPermi="['insurance:settle:remove']"-->
          <!--&gt;删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />
  </div>
</template>

<script>
import {listSettle, listSettleMain} from "@/api/insurance/settle";
import {getBaoxianlist, getDaililist, getToubaolist} from "@/api/common/common";

export default {
  name: "Settle",
  dicts: ['insure_type'],
  data() {
    return {
      baoxianList: [],
      taobaoList: [],
      beibaoList: [],
      proxyList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedTbInsuranceSettleCase: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 保险理赔信息表格数据
      settleList: [],
      // 保险理赔赔案信息表格数据
      tbInsuranceSettleCaseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        insureId: null,
        settleNum: null,
        completeNum: null,
        totalAmount: null,
        completeAmount: null,
        rate: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.initData()
    this.getList();
  },
  methods: {
    initData() {
      getToubaolist().then().then(res => {
        this.taobaoList = res.data
      })
      getBaoxianlist().then().then(res => {
        this.baoxianList = res.data
      })
      getDaililist().then().then(res => {
        this.proxyList = res.data
      })
    },
    /** 查询保险理赔信息列表 */
    getList() {
      this.loading = true;
      listSettle(this.queryParams).then(response => {
        if (response.rows) {
          this.settleList = response.rows;
          this.total = response.total;
        }
        this.loading = false;
      });
    },
    addSettle(row) {
      const insureId = row.insureId
      this.$router.push({path: "/insurance/case-list/case/" + insureId, query: {'settleId': row.id}});
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        insureId: null,
        settleNum: null,
        completeNum: null,
        totalAmount: null,
        completeAmount: null,
        rate: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.tbInsuranceSettleCaseList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加保险理赔信息";
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('insurance/settle/export', {
        ...this.queryParams
      }, `settle_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
